# This file contains the fastlane.tools configuration
# You can find the documentation at https://docs.fastlane.tools
#
# For a list of all available actions, check out
#
#     https://docs.fastlane.tools/actions
#
# For a list of all available plugins, check out
#
#     https://docs.fastlane.tools/plugins/available-plugins
#

# Uncomment the line if you want fastlane to automatically update itself
# update_fastlane

default_platform(:ios)

platform :ios do
  desc "Push a new beta build to TestFlight"

  lane :everything do
    setup
    compile
    deploy
  end

  lane :setup do
    setup_project
  end

  lane :compile do
    build
  end

  lane :deploy do
    upload_testflight
  end

  private_lane :setup_project do
    create_keychain(
      name: "keychain_name",
      password: "keychain_password",
      default_keychain: true,
      unlock: true,
      timeout: 3600,
      lock_when_sleeps: false
    )
  end

  private_lane :build do
    match(
      type: "adhoc",
      readonly: is_ci,
      keychain_name: "keychain_name",
      keychain_password: "keychain_password"
    )
    # https://docs.fastlane.tools/actions/increment_build_number/
    increment_build_number
    build_app(workspace: "Runner.xcworkspace", scheme: "Runner", export_method: "ad-hoc", include_bitcode: false, configuration: "Release")
  end

  private_lane :upload_testflight do
    # https://github.com/fastlane/fastlane/issues/13718
    ENV["DELIVER_ITMSTRANSPORTER_ADDITIONAL_UPLOAD_PARAMETERS"] = " "
    upload_to_testflight(
      username: ENV["FASTLANE_USER"],
      app_identifier: ENV["APP_IDENTIFIER"],
    )
  end

end
